package com.xu.cloud.common.process.support;

import com.xu.cloud.common.pojo.http.req.BaseRequest;
import com.xu.cloud.common.pojo.http.resp.BaseResponse;
import org.springframework.core.MethodParameter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;

import java.util.List;

/**
 * BaseRequest入参BaseResponse出参类型返回值处理器, 需要通过WebMvcConfigurer配置
 *
 * @author xuguan
 * @since 2025/1/21
 * @see WebMvcConfigurer#addArgumentResolvers(List)
 * @see WebMvcConfigurer#addReturnValueHandlers(List)
 */
public class BaseRequestResponseReturnHandler extends RequestResponseBodyMethodProcessor {

    public BaseRequestResponseReturnHandler(List<HttpMessageConverter<?>> converters, List<Object> requestResponseBodyAdvice) {
        super(converters, requestResponseBodyAdvice);
    }

    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return BaseRequest.class.isAssignableFrom(parameter.getParameterType());
    }

    @Override
    public boolean supportsReturnType(MethodParameter returnType) {
        return BaseResponse.class.isAssignableFrom(returnType.getParameterType());
    }
}
